import os

BIN_DIR=os.environ['BIN_DIR'];
LIB_DIR=os.environ['LIB_DIR'];

sources=[
  "pixman/pixman-access-accessors.c",
  "pixman/pixman-access.c",
  "pixman/pixman-bits-image.c",
  "pixman/pixman.c",
  "pixman/pixman-combine32.c",
  "pixman/pixman-combine-float.c",
  "pixman/pixman-conical-gradient.c",
  "pixman/pixman-edge-accessors.c",
  "pixman/pixman-edge.c",
  "pixman/pixman-fast-path.c",
  "pixman/pixman-filter.c",
  "pixman/pixman-general.c",
  "pixman/pixman-glyph.c",
  "pixman/pixman-gradient-walker.c",
  "pixman/pixman-image.c",
  "pixman/pixman-implementation.c",
  "pixman/pixman-linear-gradient.c",
  "pixman/pixman-matrix.c",
  "pixman/pixman-noop.c",
  "pixman/pixman-radial-gradient.c",
  "pixman/pixman-region16.c",
  "pixman/pixman-region32.c",
  "pixman/pixman-solid-fill.c",
  "pixman/pixman-timer.c",
  "pixman/pixman-trap.c",
  "pixman/pixman-utils.c",
  "pixman/pixman-mips.c",
  "pixman/pixman-arm.c",
  "pixman/pixman-x86.c",
  "pixman/pixman-ppc.c"
#  "pixman/pixman-region.c",
#  "pixman/pixman-vmx.c",
]

def useOption(key):
  return key in os.environ and os.environ[key] == 'true'
  
env=DefaultEnvironment().Clone()

OPTIMAL_CFLAGS=''
optimal_sources = []
if useOption('USE_X86_MMX'):
  print('USE_X86_MMX');
  OPTIMAL_CFLAGS=' -DUSE_X86_MMX '
  optimal_sources =  [
    "pixman/pixman-mmx.c",
  ]

if useOption('USE_SSE2'):
  print('USE_SSE2');
  OPTIMAL_CFLAGS=' -DUSE_SSE2 '
  optimal_sources =  [
  "pixman/pixman-sse2.c",
  ]

if useOption('USE_SSSE3'):
  print('USE_SSSE3');
  OPTIMAL_CFLAGS=' -DUSE_SSSE3 '
  optimal_sources =  [
  "pixman/pixman-ssse3.c",
  ]

if useOption('USE_MIPS_DSPR2'):
  print('USE_MIPS_DSPR2');
  OPTIMAL_CFLAGS=' -DUSE_MIPS_DSPR2 '
  optimal_sources =  [
    "pixman/pixman-mips-dspr2.c",
    "pixman/pixman-mips-dspr2-asm.S",
    "pixman/pixman-mips-memcpy-asm.S",
  ]

if useOption('USE_ARM_SIMD'):
  print('USE_ARM_SIMD');
  OPTIMAL_CFLAGS=' -DUSE_ARM_SIMD '
  optimal_sources =  [
    "pixman/pixman-arm-simd.c",
    "pixman/pixman-arm-simd-asm.S",
    "pixman/pixman-arm-simd-asm-scaled.S",
  ]

if useOption('USE_ARM_NEON'):
  print('USE_ARM_NEON');
  OPTIMAL_CFLAGS=' -DUSE_ARM_NEON '
  optimal_sources =  [
    "pixman/pixman-arm-neon.c",
    "pixman/pixman-arm-neon-asm-bilinear.S",
    "pixman/pixman-arm-neon-asm.S"
  ]

sources += optimal_sources;

CFLAGS=env['CFLAGS'] + OPTIMAL_CFLAGS
env.Library(os.path.join(LIB_DIR, 'pixman'), sources, CFLAGS=CFLAGS)
